package com.chenfan.ccp.plug.business.send;

import com.alibaba.fastjson.JSON;
import com.chenfan.ccp.plug.business.entity.BusinessLog;
import com.chenfan.ccp.plug.business.util.BusinessCommonsUtil;
import com.chenfan.ccp.plug.mq.util.MqTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;

/**
 * @author xutong
 */
@Slf4j
public class RocketMqLogSender extends AbstractLogSender implements Ordered {
    @Override
    public boolean send(BusinessLog businessLog) {
        boolean mqResult = MqTemplate.sendMsg(BusinessCommonsUtil.BUSINESS_LOG_TOPIC,
                JSON.toJSONString(businessLog));
        if (mqResult) {
            log.info("mq={} send success", BusinessCommonsUtil.BUSINESS_LOG_TOPIC);
            return true;
        }
        return false;
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
